﻿@using KPIS.GERP.Models.FIM
@model ChequeBook

@{
    ViewBag.SubTitle = "ทะเบียนเช็ค";

    var subModel = new Cheque();
    subModel.ChequeBookId = Model.ChequeBookId;

    var service = new KPIS.GERP.WEB.GFMS.ChequeBookService.ChequeBookServiceClient();
    var ChequeModel
        = service.SelectCheque(new KPIS.GERP.Models.FIM.Cheque { ChequeBookId = Model.ChequeBookId, RecordStatus = "!" + KPIS.GERP.Models.SYS.RecordStatus.DeletedStatus }
       ,null);
}

<div class="block-button-menu-above">
    @Html.ButtonViewAll()
    @Html.ButtonEdit(new { id = Model.ChequeBookId })
    @Html.ButtonAdd()
    @Html.ButtonDelete(new { id = Model.ChequeBookId })
</div>
    
@Html.Partial("_DetailsForm")

<hr />

@using (Html.BeginForm("DeleteAllCheque", "ChequeBook", FormMethod.Post, new { id = "indexForm" }))
{
    @Html.AntiForgeryToken()
    <div class="block-button-menu-above">
        @Html.ActionLink("เพิ่ม", "CreateCheque", "ChequeBook"
        , new { ChequeBookId = Model.ChequeBookId }
        , new { id = "cmdCreateSub", role = "button", @class = "btn btn-small btn-success button-standard-width"
            , data_dialog_id = "aboutDialog", data_dialog_title = "เพิ่ม"})
        @Html.ButtonDeleteAll()
    </div>

    <div class="alert-error">@Html.ValidationSummary()</div>
    
    <div class="row-fluid">
        <div class="table-header span12">
            <div class="span10">
            @ViewBag.SubTitle
            </div>
           <div class="row-fluid">
            <div class="table-header span12">
                <div class="span10">@ViewBag.Title</div>
                @Html.Partial("_ExportButton")
            </div>
        </div>
        </div>
    </div>

    <table id="table" class="table table-striped table-bordered table-hover" aria-describedby="table_info">
        <thead>
            <tr>
                <th class="center" style="width:50px;">
                    <label>
                        <input type="checkbox" />
                        <span class="lbl"></span>
                    </label>
                </th>
                <th>เลขที่สมุดเช็ค</th>
                <th>สถานะสมุดเช็ค</th>
                <th>หมายเหตุ</th>
      
                <th class="center" style="width:80px;">

                </th>
            </tr>
        </thead>

        <tbody>
            @foreach (var m in ChequeModel)
            {
                <tr>
                    <td class="center">
                        <label>
                            <input type="checkbox" name="deleteIds" value="@(m.ChequeId)" />
                            <span class="lbl"></span>
                        </label>
                    </td>

                    <td>
                        @Html.DisplayFor(n => m.ChequeNo)
                    </td>
                    
                        @if (Model.ChequeBookStatus == "1")
                        {
                            <td>ใช้งานอยู่ </td>
                        }
                        else{
                            <td></td>
                        }
                   
                    <td>
                        @Html.DisplayFor(n => m.Remarks)
                    </td>
                    <td class="td-actions">
                            @Html.Partial("_ButtonMenuEachRow", new ExportGrid
                                {
                                    Id = m.ChequeId,
                                    DetailsUrl = Url.Action("DetailsCheque") + "/" + m.ChequeId,
                                    EditUrl = Url.Action("EditCheque") + "/" + m.ChequeId,
                                    DeleteUrl = Url.Action("DeleteCheque") + "/" + m.ChequeId,

                                })
                    </td>
                </tr>
            }
        </tbody>
    </table>
}

<div id="modal" class="modal hide fade autosize" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="height:300px"></div>

@section scripts
{
    <script>

        $(function () {
            
            $("form #indexForm").submit(function () {
                var currentForm = this;
                bootbox.confirm(function (result) {
                    var _result = result;
                    if (result) {
                        $.ajax({
                            url: "DeleteAllCheque",
                            type: "post",
                            dataType: "json",
                            data: $(currentForm).serialize(),
                            success: function (result) {
                                if (result.success) {
                                    location.reload();
                                } else {
                                    return false;
                                }
                            }
                        });
                    }
                });
                return false;
            });
            
            var $modal = $('#modal');
            $('#cmdCreateSub, #cmdEdit, #cmdEditMini').on('click', function (e) {
                e.preventDefault();
                var url = $(this).attr('href');
                $modal.html('<iframe width="100%" height="100%" frameborder="0" scrolling="no" allowtransparency="true" src="' + url + '"></iframe>');
                $modal.modal({
                    show: true
                });
            });

            $modal.on('hide', function () {
                $modal.empty(); // Clean up
                location.reload();
                //$("#table").trigger("reloadGrid");
            });

            $('.modal-body', this).css({ width: 'auto', height: 'auto', 'max-height': '100%' });

            
        });

    </script>
}